package com.ai.planttrees.util;

/**
 * Date:  2018/4/24
 * Time:  10:11
 * Email: siy@hmgsoft.com
 * Created by siy
 */
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    public static Result fail(String msg){
        Result result = new Result();
        result.setCode(ResultCode.FAIL.getCode());
        result.setMsg(msg);
        return result;
    }

    public static Result notfound(){
        Result result = new Result();
        result.setCode(ResultCode.NOTFOUND.getCode());
        result.setMsg(ResultCode.NOTFOUND.getMsg());
        return result;
    }

    public static Result err(String msg){
        Result result = new Result();
        result.setCode(ResultCode.ERR.getCode());
        result.setMsg(msg);
        return result;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
